package main

import (
	"fmt"
	"math/rand"
	"time"
)

func multip99() {
	for i := 1; i <= 9; i++ {
		for j := 1; j <= i; j++ {
			if j == 1 {
				fmt.Printf("%d*%d=%-d ", j, i, j*i)
			} else {
				fmt.Printf("%d*%d=%-2d ", j, i, j*i)
			}

		}
        //打印分隔
		fmt.Println()
	}

}

func fib(rnum int) {
	var (
		a = 1
		b = 1
	)
	for i := 1; i <= rnum; i++ {
		if i <= 2 {
			fmt.Printf("%d ", a)
		} else {
			a, b = a+b, a
			fmt.Printf("%d ", a)
		}
	}
	fmt.Println()
}

func globalRand(maxnum int, rnum int) {
	src := rand.NewSource(time.Now().UnixNano())
	r := rand.New(src)
	var (
		n   int
		odd int
	)
	var even int = 1

	fmt.Printf("随机生成%d以内的%d个非0正整数如下：\n", maxnum, rnum)

	for i := 1; i <= rnum; i++ {
		n = r.Intn(maxnum) + 1

		if n%2 == 0 {
			even *= n
		} else {
			odd += n
		}
		fmt.Printf("%d ", n)
	}
    //\n打印分隔
	fmt.Printf("\n偶数累乘结果：%d\n", even)
	fmt.Printf("奇数累加结果：%d\n", odd)

}

func main() {
	fmt.Println("---------------------------乘法表-----------------------------")
	multip99()
	fmt.Println("-------------------------------------------------------------")
	fmt.Println("-----------------------斐波那契数列----------------------------")
	fib(100)
	fmt.Println("--------------------------------------------------------------")
	fmt.Println("-------------------------随机数-------------------------------")
	globalRand(20, 20)
	fmt.Println("-------------------------------------------------------------")
}

// 批改意见
// 1. 要求斐波那契数列100以内的值，不是第100个值；
// 2. 相加和相乘的数不是根据随机数的奇偶来处理的，而是根据索引+1的值是奇偶来处理的；